<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>事件</title>
    <style type="text/css">
        #box{
            width: 100px;
            height: 100px;
            background-color: blue;
        }
    </style>
</head>
<body>
    <div id="box"></div>
    <script type="text/javascript">
        var oDiv = document.getElementById('box');
        // oDiv.onclick = function(){
            // alert('事件被触发了');
        // }

        var isBlue = true;

        oDiv.onclick = function(){
            if(isBlue){
                // alert('事件被触发率');
                // this 指向了当前的元素节点对象
                // console.log(this);
                this.style.backgroundColor = 'red';
                isBlue = false;
            }else{
                this.style.backgroundColor = 'blue';
                isBlue = true;
            }
        };

    </script>
</body>
</html>